import axios from 'axios';

// 创建axios实例
const api = axios.create({
  baseURL: 'http://117.72.106.234:8080/api',
});

// 请求拦截器，为请求添加token
api.interceptors.request.use(
  (config) => {
    const token = localStorage.getItem('token');
    if (token) {
      config.headers.Authorization = `Bearer ${token}`;
    }
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

export const pointsService = {
  // 获取用户积分余额
  getPointsBalance: () => {
    return api.get('/points');
  },

  // 获取用户积分历史
  getPointsHistory: (params = {}) => {
    const { page = 1, size = 20, type = 'all' } = params;
    return api.get('/points/history', {
      params: { page, size, type }
    });
  },

  // 获取网络传输统计
  getNetworkTransferStats: (networkId, params = {}) => {
    const { page = 1, size = 20 } = params;
    return api.get(`/points/transfer-stats/network/${networkId}`, {
      params: { page, size }
    });
  },

  // 获取网络周期传输统计
  getNetworkWeeklyStats: (networkId, params = {}) => {
    const { page = 1, size = 20 } = params;
    return api.get(`/points/transfer-stats/network/${networkId}/weekly`, {
      params: { page, size }
    });
  }
};

export default pointsService; 